<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
include_once( "class/function_3d.php" );
require_once("class_sb/RateConfig_sb.php");
$RateConfig=new RateConfig_sb(25);
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
$mydb = new DB();
$gametype = 1;
if ($curruser['detailed_list'] == 0)
{
    $ui->showErrorPage("<p class=error>你没有权限查阅\会员下注清单！</p>");
    exit();
}
$g_betname_3or5 = judge_type($gametype, true);
$g_betname_3or5Arr = array();
foreach ($g_gametype_3d as $gameid => $val)
{
    if ($gameid == 0)
    {
        $g_betname_3or5Arr[0] = array();
    }
    else
    {
        $g_betname_3or5Arr[$gameid] = judge_type($gameid, true);
    }
}
$bettype = getvar("bettype");
$bettype = $bettype === "" ? "" : intval($bettype);
$page = getvar("page");
$page = $page == "" ? 1 : intval($page);
$agentID = getvar("agent");
$subid = intval(getvar("subid"));
$dateS = getvar("dates");
$dateE = getvar("datee");
$lid = getvar("lid");
$lid = $lid == "" ? "" : intval($lid);
$postTime = $conf->get("paper_post_bet");
$today = date("Hi") <= $postTime ? date("Y-m-d", strtotime("-1 day")) : date("Y-m-d");
if ($dateS == "" || $dateE == "" || !is_date($dateS) || !is_date($dateE))
{
    $dateS = $today;
    $dateE = $today;
}
if ($dateS == $dateE && $dateE == $today)
{
    $x = "";
}
else
{
    $x = "x";
}
$rateNum = 3;
$idsStr = "";
$ids = "";
$srcNowShowAcl = intval(getvar("srcNowShowAcl"));
if ($srcNowShowAcl && $agentID != "")
{
    if ($curruser['acl'] <= $srcNowShowAcl)
    {
        diemsg(L_NOACCESSEDIT);
    }
    if ($curruser['acl'] < 255)
    {
        $users = getuserlist($curruser['id'], $srcNowShowAcl);
        if ($users == "")
        {
            diemsg(L_NOTYOURAGENT);
        }
        if (strpos(",{$users},", ",{$agentID},") === false)
        {
            diemsg(L_NOTYOURAGENT);
        }
    }
    $ids = GetUserList($agentID);
    $idsStr = "A.user_id IN({$ids}) AND ";
}
else if ($agentID != "")
{
    $ids = intval($agentID);
    $idsStr = "A.user_id = {$ids} AND ";
}
else if ($curruser['acl'] == 255)
{
    $idsStr = "";
}
else
{
    $ids = GetUserList($curruser['id']);
    $idsStr = "A.user_id IN({$ids}) AND ";
}
if ($ids != "" || $curruser['acl'] == 255)
{
    $sql = "";
    $totalSql = "";
    $betRType = intval(getvar("betRType"));
    switch ($betRType)
    {
        case 1 :
            $whereRameSQLStr = "AND A.rame = 9 AND (A.b1 - A.a1) <= 0 ";
            $whereRameSQLStrAll = " AND A.rame = 9 AND (A.b1 - A.a1) <= 0 ";
            $rameTitleStr = " 选项:上缴";
            break;
        case 2 :
            $whereRameSQLStr = "AND A.rame = 9 AND (A.b1 - A.a1) > 0 ";
            $whereRameSQLStrAll = " AND A.rame = 9 AND (A.b1 - A.a1) > 0 ";
            $rameTitleStr = " 选项:得分";
            break;
        default :
            $whereRameSQLStr = "";
            $whereRameSQLStrAll = " AND A.rame IN (0,9) ";
            $rameTitleStr = " 选项:全部";
            break;
    }
    $showPaperFlag = true;
    $allPaperShowArr = array();
    if (isset($_GET['playCheck']))
    {
        if (in_array(0 - 1, $_GET['playCheck']))
        {
            $showPaperFlag = true;
        }
        else
        {
            foreach ($_GET['playCheck'] as $val)
            {
                $allPaperShowArr[] = $val;
            }
            if (0 < count($allPaperShowArr))
            {
                $showPaperFlag = false;
            }
        }
    }
    $sqlArr = array();
    $sqlTotalArr = array();
    if ($g_init_mode_6h && $bettype === "")
    {
        if ($conf->get("calcbet") == 1)
        {
            $ui->showErrorPage($g_gametype_3d[0]['ch'] . "颁奖过帐中，无法查询全部资料，请稍後再使用本功能！");
            exit();
        }
        else if ($conf->get("systemcheck") == 1)
        {
            $ui->showErrorPage($g_gametype_3d[0]['ch'] . "系统维謢中，无法查询全部资料，请稍後再使用本功能！");
            exit();
        }
        if (in_array(0, $allPaperShowArr) || $showPaperFlag)
        {
            $sql = "SELECT A.a1, A.b1, B.open, B.round, Q.account, A.id, A.lotto_id, A.createtime, A.bettype, 0 as subid, A.numbers, A.line_nums, A.amount, A.rate, A.rame, A.disk, A.back1, 0 as gametype, A.ip, 0 as xyid, A.rate5";
            $sql .= " FROM bet A ";
            $sql .= " LEFT JOIN lotto B ON B.id = A.lotto_id";
            $sql .= " LEFT JOIN k_user Q ON (Q.id=A.user_id)";
            $sql .= " WHERE {$idsStr} B.open BETWEEN '{$dateS}' AND '{$dateE}' {$whereRameSQLStr} ";
            array_push($sqlArr, $sql);
            $sql = "SELECT sum(A.a1) as a1, sum(A.b1) as b1, sum(A.amount) as amount, count(A.amount) as count";
            $sql .= " FROM bet A";
            $sql .= " LEFT JOIN lotto B ON B.id = A.lotto_id";
            $sql .= " WHERE {$idsStr} B.open BETWEEN '{$dateS}' AND '{$dateE}' {$whereRameSQLStrAll}";
            array_push($sqlTotalArr, $sql);
        }
    }
    if ($g_init_mode_3d)
    {
        $listShow1G = 0;
        if ($bettype !== "")
        {
            $listShow1G = intval(getvar("listShow1G"));
            $bettypeStr = " A.bettype = {$bettype} AND A.subid = {$subid} AND ";
        }
        else
        {
            $bettypeStr = "";
        }
        foreach ($g_gametype_3d as $i => $val)
        {
            if (!$g_menu_enabled[$i] || !$i)
            {
                continue;
            }
            if ($listShow1G && $i != $listShow1G)
            {
                continue;
            }
            $tplTemp = "_" . $g_gametype_3d[$i]['en'];
            if ($conf->get("calcbet{$tplTemp}") == 1)
            {
                $ui->showErrorPage($g_gametype_3d[$i]['ch'] . "颁奖过帐中，无法查询全部资料，请稍後再使用本功能！", true);
                exit();
            }
            else if ($conf->get("systemcheck{$tplTemp}") == 1)
            {
                $ui->showErrorPage($g_gametype_3d[$i]['ch'] . "系统维謢中，无法查询全部资料，请稍後再使用本功能！", true);
                exit();
            }
            if (in_array($i, $allPaperShowArr) || $showPaperFlag)
            {
                $sql = "SELECT A.a1, A.b1, B.open, B.round, Q.account, A.id, A.lotto_id, A.createtime, A.bettype, A.subid, A.numbers, A.line_nums, A.amount, A.rate, A.rame, A.disk, A.back1, {$i} as gametype, A.ip";
                $sql .= $i == 20 ? " , A.xyid " : " ,0 as xyid";
                $sql .= ", A.rate5";
                $sql .= " FROM {$x}bet{$tplTemp} A";
                $sql .= " LEFT JOIN lotto{$tplTemp} B ON B.id = A.lotto_id";
                $sql .= " LEFT JOIN k_user Q ON (Q.id=A.user_id)";
                $sql .= " WHERE {$idsStr} {$bettypeStr} B.open BETWEEN '{$dateS}' AND '{$dateE}' {$whereRameSQLStr} ";
                array_push($sqlArr, $sql);
                $sql = "SELECT sum(A.a1) as a1, sum(A.b1) as b1, sum(A.amount) as amount, count(A.amount) as count";
                $sql .= " FROM {$x}bet{$tplTemp} A";
                $sql .= " LEFT JOIN lotto{$tplTemp} B ON B.id = A.lotto_id";
                $sql .= " WHERE {$idsStr} {$bettypeStr} B.open BETWEEN '{$dateS}' AND '{$dateE}' {$whereRameSQLStrAll}";
                array_push($sqlTotalArr, $sql);
            }
        }
    }
    if (0 < count($sqlArr))
    {
        $sql = implode(" UNION ALL ", $sqlArr);
        $sql .= " ORDER BY createtime DESC, id DESC";
        $rs = getdb($sql, $page, 20);
    }
    else
    {
        $ui->showErrorPage("无勾选任何玩法");
    }
    $littleNum = 0;
    $littleAmount = 0;
    $littleBack = 0;
    $littleB1 = 0;
    if ($curruser['acl'] == 255)
    {
        $ipshowFlag = 1;
    }
    else if (intval($conf->Get("ipshow")))
    {
        $ipshowFlag = 1;
    }
    else
    {
        $ipshowFlag = 0;
    }
    $xyidTitle = array(0 => "", 1 => "X盘", 2 => "Y盘");
    $ui->header();
    $strTemp = "<a href=\"javascript:history.back();\">回上一页</a>";
    echo "<style>";
    echo ".title0, .td0{background-color:#CCCC7F; color:#000;}";
    echo ".td1{background-color:#CCCC9F; color:#000;}";
    echo "</style>";
    $typeStr = $bettype === "" ? "全部" : $g_betname_3d[$bettype];
    echo title("全部 下注清单&nbsp;&nbsp;{$dateS}～{$dateE}&nbsp;&nbsp;种类:{$typeStr}&nbsp;&nbsp;{$rameTitleStr}", "<a href=\"javascript:window.print()\">列印</a>&nbsp;|&nbsp;{$strTemp}", 900);
    echo "<table width=900 border=1 cellpadding=3 cellspacing=0>";
    echo "<tr class=\"paperAll\" align=center><td nowrap>单号 / 时间</td><td nowrap>会员 / 退水</td><td nowrap>下注玩法</td><td nowrap>盘类 / 期数 / 开奖日期</td><td nowrap>下注内容</td><td nowrap>下注金额</td><td nowrap>赔率</td><td nowrap>退水</td><td nowrap>结果</td><td nowrap>备注</td><td nowrap>IP</td></tr>";
    while (!$rs->eof)
    {
        echo "<tr class=\"td2\">";
        echo "<td nowrap><font color=\"green\">" . $rs->f['id'] . "</font>&nbsp;&nbsp;" . date("m-d H:i:s", $rs->f['createtime']) . "</td>";
        echo "<td nowrap>" . $rs->f['account'] . "&nbsp;&nbsp;<font color=\"green\">" . round(100 - $rs->f['back1'], 2) . "</font></td>";
        echo "<td nowrap class=\"paper" . $g_gametype_3d[$rs->f['gametype']]['en'] . "\">" . $g_gametype_3d[$rs->f['gametype']]['ch'] . "</td>";
        echo "<td nowrap>" . $g_disk_name[$rs->f['disk']] . "&nbsp;/&nbsp;" . $rs->f['round'] . "期&nbsp;<font color=\"green\">" . $rs->f['open'] . "</font></td>";
        if ($rs->f['gametype'] == 0)
        {
            echo "<td nowrap>" . GetBetContent($rs->f['bettype'], $rs->f['numbers'], $rs->f['amount']) . "</td>";
        }
		elseif ($rs->f['gametype'] == 25 || $rs->f['gametype'] == 26)
		{
			echo "<td nowrap>";
            echo "【" . $g_betname_3or5Arr[$rs->f['gametype']][$rs->f['bettype']] . "】&nbsp;" . $RateConfig->getBetContent($rs->f['bettype'],$rs->f['line_nums']) . "</td>";	
		}
        else
        {
            echo "<td nowrap>";
            if ($rs->f['gametype'] == 20)
            {
                echo "<font class='colorXY'>" . $xyidTitle[$rs->f['xyid']] . "</font>";
            }
            echo "【" . $g_betname_3or5Arr[$rs->f['gametype']][$rs->f['bettype'] . "_" . $rs->f['subid']] . "】&nbsp;" . nl2br($rs->f['line_nums']) . "</td>";
        }
        if (20000 < $rs->f['amount'])
        {
            $color = "alert2";
        }
        else if (10000 < $rs->f['amount'])
        {
            $color = "alert1";
        }
        else
        {
            $color = "";
        }
        echo "<td nowrap align=\"right\" class=\"" . $color . "\">" . $rs->f['amount'] . "</td>";
        echo "<td nowrap align=\"right\">" . floatval($rs->f['rate']) . "</td>";
        echo "<td nowrap align=\"right\">" . round($rs->f['a1'], 2) . "</td>";
        echo "<td nowrap align=\"right\">" . say_numbercolor($rs->f['b1'], $rateNum) . "</td>";
        if ($rs->f['rame'] == 1)
        {
            $note = "<font color=red>- 逾时 -</font>";
        }
        else if ($rs->f['rame'] == 2)
        {
            $note = "<font color=red>- 取消 -</font>";
        }
        else if ($rs->f['rame'] == 3)
        {
            $note = "<font color=red>- 异常 -</font>";
        }
        else
        {
            $note = "";
            $littleNum += 1;
            $littleAmount += $rs->f['amount'];
            $littleBack += $rs->f['a1'];
            $littleB1 += $rs->f['b1'];
        }
        if (chkBet_peace($rs->f))
        {
            $note .= " <font class='betpeace'>和局</font>";
        }
        if ($curruser['acl'] == 255)
        {
            $note .= floatval($rs->f['rate5']) ? "<font class=\"c5\" color=\"red\">[" . floatval($rs->f['rate5']) . "]</font>" : "";
        }
        echo "<td nowrap>" . $note . "</td>";
        echo "<td nowrap>" . ( $ipshowFlag ? $rs->f['ip'] : "" ) . "</td>";
        echo "</tr>";
        $rs->movenext();
    }
    if (1 < $rs->totalpages)
    {
        echo "<tr align=\"right\" class=\"td1\"><td colspan=\"5\">小计 " . $littleNum . " 笔</td><td nowrap>" . $littleAmount . "</td><td>--</td><td nowrap>" . round($littleBack, 2) . "</td><td nowrap>" . say_numbercolor(round($littleB1, $rateNum), $rateNum) . "</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
    }
    $totalrecords = 0;
    $totalAmount = 0;
    $totalA1 = 0;
    $totalB1 = 0;
    if (0 < count($sqlTotalArr))
    {
        $sql = implode(" UNION ALL ", $sqlTotalArr);
        $rs2 = getdb($sql);
        if (!$rs2->eof)
        {
            while (!$rs2->eof)
            {
                $totalrecords += $rs2->f['count'];
                $totalAmount += $rs2->f['amount'];
                $totalA1 += $rs2->f['a1'];
                $totalB1 += $rs2->f['b1'];
                $rs2->next();
            }
            echo "<tr align=\"right\" class=\"td3\"><td colspan=\"5\">总计 " . $totalrecords . " 笔</td><td nowrap>" . $totalAmount . "</td><td>--</td><td nowrap>" . round($totalA1, 2) . "</td><td nowrap>" . say_numbercolor(round($totalB1, $rateNum), $rateNum) . "</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
        }
    }
    echo "<tr><td class=\"paperAll\" colspan=\"11\">" . $rs->pagelink() . "</td></tr>";
    echo "</table>";
    echo "<script language=\"JavaScript\"> \r\n$(\"tbody tr[class=td2]\").hover(\r\n  function() {\$(this).addClass(\"trover\");}\r\n  , function() {\$(this).removeClass(\"trover\");}\r\n);\r\n</script>\r\n<br />  \r\n";
    $ui->footer();
}
else
{
    $ui->showErrorPage("你的下线无任何会员");
    exit();
}
?>